package br.com.hotel68.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity implementation class for Entity: Room
 *
 */
@SuppressWarnings("serial")
@Entity
public class Hosting implements Serializable {

	@Id    
	private Integer id;
	@Temporal(TemporalType.TIME)
	private Date checkin;
	@Temporal(TemporalType.TIME)
	private Date checkout;
	@Enumerated(EnumType.STRING)
	private HostingStatus status;
	
	@ManyToOne
	@JoinColumn(name="room_id", nullable = false, referencedColumnName="id")
	private Room room;
	
	@ManyToOne
	@JoinColumn(name="client_id", nullable = false, referencedColumnName="id")
	private Client client;
	
	@OneToMany(mappedBy="hosting")
	private List<HostingExpense> expenses;

	
	public Hosting() {
		super();
	}   

	public Hosting(int _id) {
		this.id = _id;
	}

	public Integer getId() {
		return this.id;
	}
	public void setId(Integer id) {
		this.id = id;
	}

	public Date getCheckin() {
		return checkin;
	}
	public void setCheckin(Date checkin) {
		this.checkin = checkin;
	}

	public Date getCheckout() {
		return checkout;
	}
	public void setCheckout(Date checkout) {
		this.checkout = checkout;
	}

	public HostingStatus getStatus() {
		return status;
	}
	public void setStatus(HostingStatus status) {
		this.status = status;
	}

	public Room getRoom() {
		return room;
	}
	public void setRoom(Room room) {
		this.room = room;
	}

	public Client getClient() {
		return client;
	}
	public void setClient(Client client) {
		this.client = client;
	}

	public List<HostingExpense> getExpenses() {
		return expenses;
	}
	public void addExpense(HostingExpense expense) {
		this.expenses.add(expense);
	}
	
	public double getTotalExpenses() {
		Double total = 0d;
		for (HostingExpense expense : this.expenses) {
			total = expense.getValue();
		}
		return total;
	}
	
}
